﻿package java_45;

import java.util.InputMismatchException;
import java.util.Scanner;

import org.apache.log4j.Logger;


public class jisuanqi {
	private static Logger logger=Logger.getLogger(jisuanqi.class.getName());
		public static void main(String[] args) {
			try{
				Scanner input=new Scanner(System.in);
			System.out.println("请输入第一个数");
			int num=input.nextInt();
			logger.debug("请输入第一个数" + num);
			System.out.println("请输入第二个数");
			int num2=input.nextInt();
			logger.debug("请输入第二个数" + num2);
			System.out.println("请输入符号 1.+ 2.- 3.* 4./");
			int fu=input.nextInt();
			switch (fu) {
			case 1:

	            System.out.println(String.format("%d + %d = %d", 
	                    num, num2, num+ num2));
				logger.debug("和是:" + String.format("num+num2"));
				break;
			case 2:
				System.out.println(String.format("%d - %d = %d", 
	                    num, num2, num- num2));
				logger.debug("差是:" + String.format("num-num2"));
				break;
			case 3:
				System.out.println(String.format("%d * %d = %d", 
	                    num, num2, num* num2));
				logger.debug("积是:" + String.format("num*num2"));
				break;
			case 4:
				System.out.println(String.format("%d / %d = %d", 
	                    num, num2, num/ num2));
				logger.debug("商是:" + String.format("num/num2"));
				break;
			}
			}catch (InputMismatchException e) {				
				logger.error(e.getMessage() + "请输入合法数字和符号");
			
				}
				catch (NullPointerException e) {				
					logger.error(e.getMessage() + "除数不能为零");
				
			}
			catch(ArrayStoreException e){
				logger.error(e.getMessage());
				
			}
			catch (Exception e)
			{				
				logger.error(e.getMessage());
				
				}
			finally{
				System.out.println("感谢使用");
			}
		}
}
